package org.spring.aicloud.task;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.spring.aicloud.entity.User;
import org.spring.aicloud.service.IUserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class TimedTask {

    @Resource
    private IUserService userService;
    @Value("${system.usecount}")
    private int useCount;
    /**
     * 重置用户使用次数的定时任务
     */
    @XxlJob("resetUserUseCount")
    public void resetUserUserCount() {
        UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("usecount",useCount);
        //失败的时候要知道
        boolean update = userService.update(updateWrapper);
        if (!update){
            //todo:调用通知中心通知相关负责人排查和解决问题
        }
    }
}
